/*
* Accord Software, Inc.
*
* Tutorial 11 - CIDL file.
*
* Sending array of structures and returning a
* struct via reference and directly.
*/
#include "s_array.h"
/*
* return struct coord *
*/
struct coord *
sp_array(sp)
struct coord sp[COUNT];
{
static char *p = "returned by reference";
static struct coord retval;
int j;
memset(&retval, 0, sizeof(struct coord));
for (j = 0; j < COUNT; j++) {
retval.x += sp[j].x;
retval.y += sp[j].y;
retval.z += sp[j].z;
printf("%d %d %d %s\n",
sp[j].x, sp[j].y, sp[j].z, sp[j].token);
}
retval.token = p;
return &retval;
}
/*
* return struct coord
*
* remember to zero out pointers
*/
struct coord
s_array(sp)
struct coord sp[COUNT];
{
static char *d = "returned directly";
struct coord *rp;
struct coord r;
memset(&r, 0, sizeof(struct coord));
rp = sp_array(sp);
r.x = rp->x;
r.y = rp->y;
r.z = rp->z;
r.token = d;
return r;
}